package com.fangcang.log.tracelog;

import org.apache.log4j.Level;

/**
 * @ClassName: com.fangcang.redis.log.Xtrace
 * @Description: 自定义一个日志级别：XTRACE
 * @author jilong.xiao
 * @date 2018年11月28日
 */
public class Xtrace extends Level {
	private static final long serialVersionUID = 1L;

	protected Xtrace(int level, String levelStr, int syslogEquivalent) {
		super(level, levelStr, syslogEquivalent);
	}
	/**
	 * 自定义log的权重，介于OFF和FATAL之间
	 */
	public static final int XTRACE_INT = OFF_INT - 10;
	public static final Level XTRACE = new Xtrace(XTRACE_INT,"XTRACE",10);
	
	public static Level toLevel(String logArgument) {
        if (logArgument != null && logArgument.toUpperCase().equals("XTRACE")) {
            return XTRACE;
        }
        return (Level) toLevel(logArgument);
    }
 
    public static Level toLevel(int val) {
        if (val == XTRACE_INT) {
            return XTRACE;
        }
        return (Level) toLevel(val, Level.DEBUG);
    }
 
    public static Level toLevel(int val, Level defaultLevel) {
        if (val == XTRACE_INT) {
            return XTRACE;
        }
        return Level.toLevel(val, defaultLevel);
    }
 
    public static Level toLevel(String logArgument, Level defaultLevel) {
        if (logArgument != null && logArgument.toUpperCase().equals("XTRACE")) {
            return XTRACE;
        }
        return Level.toLevel(logArgument, defaultLevel);
    }
}
